#include "output.h"

Output::Output(void)
{
	this->pat.clear();
	/*this->pat.push_back(new Pattern());
	this->pat.back()->addPixel(2,7);
	this->pat.push_back(new Pattern());
	this->pat.push_back(new Pattern());
	this->pat.back()->addPixel(2,2);
	this->pat.back()->addPixel(5,0);*/
	
	this->imagem = new Image[3];
	
}

Output::~Output(void){
	this->pat.clear();
	if(this->imagem != NULL)delete[] this->imagem;
}

bool Output::writeFile(const char *file)
{
	fstream save(file,ifstream::out);
	cout<<"Saving "<<file<<endl;
	//Salvando imagens
	for(register int y = imagem[0].h()-1; y >= 0;--y){
		for(register int x = 0; x < imagem[0].w();++x){
			save<<imagem[0].getPixel(x,y)<<' ';
		}
		save<<'\n';
	}save<<'\n';
	for(register int y = imagem[1].h()-1; y >= 0;--y){
		for(register int x = 0; x < imagem[1].w();++x){
			save<<imagem[1].getPixel(x,y)<<' ';
		}
		save<<'\n';
	}save<<'\n';
	for(register int y = imagem[2].h()-1; y >= 0;--y){
		for(register int x = 0; x < imagem[2].w();++x){
			save<<imagem[2].getPixel(x,y)<<' ';
		}
		save<<'\n';
	}save<<'\n';
	
	
	
	for(register int i = 0; i < (int)pat.size();++i){
		if(pat[i]->size()){
			for(register int j = 0; j < pat[i]->size();++j){
				save<<'('<<pat[i]->getPixelX(j)<<','<<pat[i]->getPixelY(j)<<") ";
			}
		}
		save<<'\n';
	}
	save.close();
	return true;
}

void Output::print(void)
{
	cout<<"Saida->Imagens: "<<endl;
	imagem[0].print();cout<<endl;
	imagem[1].print();cout<<endl;
	imagem[2].print();cout<<endl;
	
	cout<<"Saida->Padroes: "<<endl;
	for(register int i = 0; i < (int)pat.size();++i){
		cout<<'\t'<<i<<": ";
		if(pat[i]->size()){
			for(register int j = 0; j < pat[i]->size();++j){
				cout<<'('<<pat[i]->getPixelX(j)<<','<<pat[i]->getPixelY(j)<<") ";
			}
		}
		cout<<endl;
	}
}
